home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / CHAP13.TXT < prev    next >
Text File  |  1989-12-30  |  5KB  |  125 lines

  1.                  Chapter 13 - Character and Bit Manipulation
  2.  
  3.  
  4.                             UPPER AND LOWER CASE
  5.  
  6.              Load  and display the program UPLOW.C for an example of 
  7.         a  program that does lots of character  manipulation.   More 
  8.         specifically,  it changes the case of alphabetic  characters 
  9.         around.   It illustrates the use of four functions that have 
  10.         to  do with case.   It should be no problem for you to study 
  11.         this program on your own and understand how it  works.   The 
  12.         four functions on display in this program are all within the 
  13.         user written function,  "mix_up_the_line".   Compile and run 
  14.         the  program  with  the  file  of  your  choice.   The  four 
  15.         functions are;
  16.  
  17.              isupper();     Is the character upper case?
  18.              islower();     Is the character lower case?
  19.              toupper();     Make the character upper case.
  20.              tolower();     Make the character lower case.
  21.  
  22.                         CLASSIFICATION OF CHARACTERS
  23.  
  24.              Load  and display the next program,  CHARCLAS.C for  an 
  25.         example of character counting.   We have repeatedly used the 
  26.         backslash  n character representing a new line.   There  are 
  27.         several  others that are commonly used,  so they are defined 
  28.         in the following table;
  29.  
  30.              \n             Newline
  31.              \t             Tab
  32.              \b             Backspace
  33.              \"             Double quote
  34.              \\             Backslash
  35.              \0             NULL (zero)
  36.  
  37.              By  preceding  each of the above  characters  with  the 
  38.         backslash character, the character can be included in a line 
  39.         of text for display,  or printing.   In the same way that it 
  40.         is  perfectly  all right to use the letter "n" in a line  of 
  41.         text as a part of someone's name, and as an end-of-line, the 
  42.         other  characters can be used as parts of text or for  their 
  43.         particular functions. 
  44.  
  45.              The program on your screen uses the functions that  can 
  46.         determine   the  class  of  a  character,   and  counts  the 
  47.         characters  in  each class.   The number of  each  class  is 
  48.         displayed  along with the line itself.   The three functions 
  49.         are as follows;
  50.  
  51.              isalpha();     Is the character alphabetic?
  52.              isdigit();     Is the character a numeral?
  53.              isspace();     Is the character any of, \n, \t, 
  54.                               or blank?
  55.  
  56.  
  57.                                    Page 92
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                  Chapter 13 - Character and Bit Manipulation
  68.  
  69.  
  70.  
  71.              This program should be simple for you to find your  way 
  72.         through  so no explanation will be given.   It was necessary 
  73.         to give an example with these functions used.   Compile  and 
  74.         run this program with any file you choose.
  75.  
  76.                            THE LOGICAL FUNCTIONS
  77.  
  78.              Load and display the program BITOPS.C. The functions in 
  79.         this  group of functions are used to do bitwise  operations, 
  80.         meaning  that  the operations are performed on the  bits  as 
  81.         though they were individual bits.   No carry from bit to bit 
  82.         is performed as would be done with a binary addition.   Even 
  83.         though  the operations are performed on a single bit  basis, 
  84.         an entire byte or integer variable can be operated on in one 
  85.         instruction.   The operators and the operations they perform 
  86.         are given in the following table;
  87.  
  88.              &    Logical AND, if both bits are 1, the result is 1.
  89.              |    Logical OR, if either bit is one, the result is 1.
  90.              ^    Logical XOR,  (exclusive OR),  if one and only one 
  91.                     bit is 1, the result is 1.
  92.              ~    Logical invert,  if the bit is 1, the result is 0, 
  93.                     and if the bit is 0, the result is 1.
  94.  
  95.              The  example  program  uses  several  fields  that  are 
  96.         combined  in each of the ways given above.   The data is  in 
  97.         hexadecimal  format.   It  will be assumed that you  already 
  98.         know hexadecimal format if you need to use these operations.  
  99.         If  you  don't,  you  will need to study  it  on  your  own.  
  100.         Teaching  the  hexadecimal format of numbers is  beyond  the 
  101.         scope of this tutorial.
  102.  
  103.              Run the program and observe the output.
  104.  
  105.                            THE SHIFT INSTRUCTIONS
  106.  
  107.              The  last two operations to be covered in this  chapter 
  108.         are  the left shift and the right shift instructions.   Load 
  109.         the example program SHIFTER.C for an example using these two 
  110.         instructions.    The   two  operations  use  the   following 
  111.         operators;
  112.  
  113.              << n      Left shift n places.
  114.              >> n      Right shift n places.
  115.  
  116.              Once again the operations are carried out and displayed 
  117.         using the hexadecimal format.   The program should be simple 
  118.         for you to understand on your own, there is no tricky code.
  119.  
  120.  
  121.  
  122.  
  123.                                    Page 93
  124.  
  125.